class Exploitdb < Formula
  desc "Database of public exploits and corresponding vulnerable software"
  homepage "https://www.exploit-db.com/"
  url "https://github.com/offensive-security/exploitdb.git",
      tag:      "2022-01-20",
      revision: "034f9fe70ce9831edf4e80ea8b916a65097d85e9"
  version "2022-01-20"
  license "GPL-2.0-or-later"
  head "https://github.com/offensive-security/exploitdb.git", branch: "master"

  bottle do
    sha256 cellar: :any_skip_relocation, arm64_monterey: "c612ecbc76448058cad9b9f22adb36cf6d06e32e86b79b1ff11b14783dedf788"
    sha256 cellar: :any_skip_relocation, arm64_big_sur:  "7378e540de0b59bca58a0238cfa188a5258394d26eacfbffae568d5548ae3e64"
    sha256 cellar: :any_skip_relocation, monterey:       "178dd04f46cc6543d00d9a7d663692075c593e021d257fc9a7ee074a000a3173"
    sha256 cellar: :any_skip_relocation, big_sur:        "34155ec4b5c47811f91f076b5b469aa758859ac37aa0abe1115243ef15889e55"
    sha256 cellar: :any_skip_relocation, catalina:       "8beadb74d4920fd653b12fb85bf17725aad450519b3e880cbc0081f3851267ae"
    sha256 cellar: :any_skip_relocation, x86_64_linux:   "e530ad3ab5e530c0d4f93564502411d34b4bf6367c591b5d035a766829e7c22e"
  end

  def install
    inreplace "searchsploit",
              "rc_file=\"\"", "rc_file=\"#{etc}/searchsploit_rc\""

    optpath = opt_share/"exploitdb"
    inreplace ".searchsploit_rc" do |s|
      s.gsub! "\"/opt/exploitdb\"", optpath
      s.gsub! "\"/opt/exploitdb-papers\"", "#{optpath}-papers"
    end

    bin.install "searchsploit"
    etc.install ".searchsploit_rc" => "searchsploit_rc"

    pkgshare.install %w[.git exploits files_exploits.csv files_shellcodes.csv
                        shellcodes]
  end

  test do
    system "#{bin}/searchsploit", "sendpage"
  end
end
